/////////////// STATISTICS /////////////
//  
function renderRealPaymentStatisticAjax() {
    $.ajax({
            type:       "GET",
            url:        "renderRealPaymentStatisticsAjax?set_ajax_view",  
            data:       "start_date=" + $('#date_range').val() +
                        "&end_date=" + $('#date_range').val() +
                        "&department_id=" + $('#department_id option:selected').val() +
                        "&cashier_id=" + $('#cashier_id').val(),                
            dataType:   "json",
            beforeSend: function() {
                $('div#innerLoading').show();                 
            },
            complete:   function() {
                $('div#innerLoading').hide();
            },
            success:  function(data) {
	            if (data.error.code == 'OK') {
	                var date = $('#date_range').val();                                                          
	                $('#choosen_day').text(_('Real payment statistics: {0}/{1}/{2}',date.substring(5, 7) ,date.substring(8), date.substring(0, 4)));
	                $('#content_ticket_item').html(data.result);                                                                       
	                if ($('#ticket_item tbody').children().length > 0) {
	                    // Initializing is sorting on Time ASC and Name ASC
	                    $('#ticket_item').tablesorter();
	                    $('#pagination').show();    
	                    //var sorter = [[3,0], [1,0]];
	                    //$('#ticket_item').trigger("sorton", [sorter]);
	                                                                
	                    $('#ticket_item')                       
	                        .tablesorterPager({
	                        container: $("#pagination"),                                                
	                        positionFixed: false
	                        });;                    
	                } else {
	                    $('#pagination').hide();
	                }         
	            }
	            else {
	                displayError(data.error.mess);              
	            }                                   
            }            
        });
}

function renderInsuranceStatisticAjax() {   
    $.ajax({
            type:       "GET",
            url:        "RenderInsuranceStatisticAjax?set_ajax_view",
            data:       "start_date=" + $('#date_range').val() +
                        "&end_date=" + $('#date_range').val(),                  
            beforeSend: function() {                
                $('div#innerLoading').show();                               
            },
            complete:   function() {
                $('div#innerLoading').hide();                   
            },
            success:    function(data) {
                var date = $('#date_range').val();              
                // $('#date_range :selected').attr('label')                                         
                $('#choosen_day').text(_('Insurance statistics: {0}/{1}/{2}', date.substring(5, 7), date.substring(8) , date.substring(0, 4)));
                
                $('#content_ticket_item').html(data);
                styleTicketItemTable($('#ticket_item'));    
                styleTotalTable($('#total_table')); 
                                                                                                                                                                                
                if ($('#ticket_item tbody').children().length > 0) {
                    $('#pagination').show();
                                                    
                    $('#ticket_item').tablesorter();                                                                            
                    // Initializing is sorting on Time ASC and Name ASC
                    //var sorter = [[2,1], [1,0]];                                                                                                                                                                                      
                    //$('#ticket_item').trigger("sorton", [sorter]);
                    $('#ticket_item').tablesorterPager({
                        container: $("#pagination"),                                                
                        positionFixed: false
                    });                 
                                                                                                                    
                } else {
                    $('#pagination').hide();
                }                                                                                                                           
            }
            
        });
}